package cn.com.surker.oa.service.impl;

import cn.com.surker.enums.StateEnum;
import cn.com.surker.oa.dao.OaSupplierOrgDao;
import cn.com.surker.oa.entity.OaSupplierOrg;
import cn.com.surker.oa.service.OaSupplierOrgService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * erp供应商站点对应表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2024-03-07
 */
@Service
public class OaSupplierOrgServiceImpl extends ServiceImpl<OaSupplierOrgDao, OaSupplierOrg> implements OaSupplierOrgService {

	@Resource
	private OaSupplierOrgDao oaSupplierOrgDao;

	@Override
	public OaSupplierOrg querySupOrg(Long supplierId, Long orgId, Integer type) {
		QueryWrapper<OaSupplierOrg> qw = new QueryWrapper<>();
		qw.eq("status", StateEnum.ENABLED.getCode());
		if (supplierId != null) {
			qw.eq("supplier_id", supplierId);
		}
		if (orgId != null) {
			qw.eq("org_id", orgId);
		}
		if (type != null) {
			qw.eq("type", type);
		}
		List<OaSupplierOrg> oaSupplierOrgs = oaSupplierOrgDao.selectList(qw);
		if (oaSupplierOrgs != null && oaSupplierOrgs.size() > 0) {
			OaSupplierOrg oaSupplierOrg = oaSupplierOrgs.get(0);
			return oaSupplierOrg;
		} else {
			return null;
		}
	}
}